package com.qqtech.qquan.user.service;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.qqtech.core.common.util.TimeUtil;
import com.qqtech.core.frame.dao.BaseDao;
import com.qqtech.core.frame.service.BaseServiceImpl;
import com.qqtech.qquan.user.dao.UserWithdrawDao;
import com.qqtech.qquan.user.enums.UserWithdrawStatusDictEnum;
import com.qqtech.qquan.user.model.UserMoneyLog;
import com.qqtech.qquan.user.model.UserWithdraw;
import com.qqtech.qquan.user.model.UserWithdrawQuery;
import com.qqtech.qquan.user.model.UserWithdrawVo;

@Service
public class UserWithdrawServiceImpl extends BaseServiceImpl<UserWithdraw>implements UserWithdrawService {
	public static final Logger log = LoggerFactory.getLogger(UserWithdrawServiceImpl.class);

	@Resource
	private UserWithdrawDao userWithdrawDao;

	@Resource
	private UserMoneyLogService userMoneyLogService;

	@Override
	protected BaseDao<UserWithdraw> getBaseDao() {
		return userWithdrawDao;
	}

	@Override
	public int handleConfirm(Integer id) {
		UserWithdrawVo userWithdrawVo = userWithdrawDao.getById(id);
		UserMoneyLog userMoneyLog = new UserMoneyLog();
		userMoneyLog.setUserId(userWithdrawVo.getUserId());
		userMoneyLog.setMoney(-userWithdrawVo.getCash().intValue()*100);
		userMoneyLog.setRemark("余额提现"+userWithdrawVo.getCash());
		int userMoneyLogId=userMoneyLogService.insert(userMoneyLog);
		userWithdrawVo.setStatus(UserWithdrawStatusDictEnum.FINISHED.getCode());
		userWithdrawVo.setStatusAt(TimeUtil.now());
		return userWithdrawDao.updateById(userWithdrawVo);
	}

	@Override
	public List<UserWithdraw> getHandleMoney(UserWithdrawVo userWithdrawVo) {
		return userWithdrawDao.getHandleMoney(userWithdrawVo);
	}

	@Override
	public int handleCancle(Integer id,String remark) {
		UserWithdrawVo userWithdrawVo=userWithdrawDao.getById(id);
		userWithdrawVo.setStatus(UserWithdrawStatusDictEnum.REJECTED.getCode());
		userWithdrawVo.setStatusAt(TimeUtil.now());
		userWithdrawVo.setRemark(remark);
		return userWithdrawDao.updateById(userWithdrawVo);
	}
	
	@Override
	public Page<UserWithdrawVo> queryPageListAdmin(UserWithdrawQuery query, Pageable pageable) {
		return userWithdrawDao.queryPageListAdmin(query, pageable);
	}

	@Override
	public List<UserWithdrawVo> queryList4Excel(UserWithdrawQuery query, Pageable pageable) {
		return userWithdrawDao.queryList4Excel(query, pageable);
	}
	@Override
	public BigDecimal querySumCash(UserWithdrawQuery query){
		return userWithdrawDao.querySumCash(query);
		
	}
}